package com.ruanyun.modular.admin.mapper;

import com.ruanyun.modular.admin.entity.TPollutantsFactor;
import com.ruanyun.modular.admin.model.params.TPollutantsFactorParam;
import com.ruanyun.modular.admin.model.result.TPollutantsFactorResult;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 污染物信息表 Mapper 接口
 * </p>
 *
 * @author zs
 * @since 2021-05-12
 */
@Repository
public interface TPollutantsFactorMapper extends BaseMapper<TPollutantsFactor> {

    /**
     * 获取列表
     *
     * @author zs
     * @Date 2021-05-12
     */
    List<TPollutantsFactorResult> customList(@Param("paramCondition") TPollutantsFactorParam paramCondition);

    /**
     * 获取map列表
     *
     * @author zs
     * @Date 2021-05-12
     */
    List<Map<String, Object>> customMapList(@Param("paramCondition") TPollutantsFactorParam paramCondition);

    /**
     * 获取分页实体列表
     *
     * @author zs
     * @Date 2021-05-12
     */
    Page<TPollutantsFactorResult> customPageList(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);

    /**
     * 获取分页map列表
     *
     * @author zs
     * @Date 2021-05-12
     */
    Page<Map<String, Object>> customPageMapList(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);


    Page<TPollutantsFactorResult> customPageList1(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);

    Page<TPollutantsFactorResult> pollutantsList(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);

    /*获取有组织排放口信息*/
    Page<TPollutantsFactorResult> getOrganizedInfo(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);

    Page<TPollutantsFactorResult> getOrganizedPollutantsInfo(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);

    /*获取无组织场内信息*/
    Page<TPollutantsFactorResult> getUnorganizedLocationInfo(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);


    /*获取厂内污染物信息*/

    Page<TPollutantsFactorResult> getInsidePollutantsInfo(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);



    Page<TPollutantsFactorResult> getUnInsidePollutantsInfo(@Param("page") Page page, @Param("paramCondition") TPollutantsFactorParam paramCondition);



    /*导出报告有组织排放口污染无信息*/
    @Select("SELECT\n" +
            "\ta.*, b.orifice_name AS orificeName\n" +
            "FROM\n" +
            "\tt_pollutants_factor a\n" +
            "LEFT JOIN t_exhaust_orifice b ON a.orifice_id = b.id\n" +
            "LEFT JOIN t_monitoringinfo m on a.monitoring_id = m.id\n" +
            "WHERE\n" +
            "\ta.del_flag != 2\n" +
            "AND b.del_flag != 2\n" +
            "and m.company_id = #{companyId}\n" +
            "AND a.is_organization = 1")
    List<TPollutantsFactorResult> getOrganizedList(@Param("companyId") Integer companyId);


    /*导出报告无组织厂界污染信息*/
    @Select(" SELECT\n" +
            "            a.*\n" +
            "        FROM\n" +
            "            t_pollutants_factor a\n" +
            "        LEFT JOIN t_exhaust_orifice b ON a.orifice_id = b.id\n" +
            "LEFT JOIN t_monitoringinfo m on a.monitoring_id = m.id\n" +
            "        WHERE\n" +
            "            a.del_flag != 2\n" +
            "       \n" +
            "        AND a.is_organization = 2\n" +
            "        AND a.is_inside = 1\n" +
            "       and a.wind_type = #{windType}\n" +
            "         and m.company_id = #{companyId}\n")
    List<TPollutantsFactorResult> getUnOrganizedList(@Param("companyId") Integer companyId,@Param("windType") Integer windType);


    /*导出报告无组织厂内污染信息*/
     @Select(" SELECT\n" +
             "            a.*,a1.positions positionName \n" +
             "        FROM\n" +
             "            t_pollutants_factor a\n" +
             "        LEFT JOIN t_exhaust_orifice b ON a.orifice_id = b.id\n" +
             "LEFT JOIN t_monitoringinfo m on a.monitoring_id = m.id\n" +
             " LEFT JOIN t_pollutants_factor a1 on a.pid = a1.id\n" +
             "        WHERE\n" +
             "            a.del_flag != 2\n" +
             "       \n" +
             "        AND a.is_organization = 2\n" +
             "        AND a.is_inside = 2\n" +
             "         and m.company_id = #{companyId}\n" +
             "and a.pid != 0\n")
    List<TPollutantsFactorResult>  getInsidePositionList(@Param("companyId") Integer companyId);

}
